using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using System.Collections;
using System.IO;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modExportToNano
	{
		public static void ExportNano(clsProject cProject)
		{
			//Discarded unreachable code: IL_01eb, IL_0202, IL_020d, IL_021d, IL_02af, IL_02b1, IL_02c5, IL_02e7
			int num = default(int);
			int num5 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				string text = Path.Combine(cProject.ProjectPath(), "Exported Nano Text.txt");
				num2 = 3;
				int num3 = (int)clsShared.cLang.TransMsgBox("Include unused chapters and scenes?", MsgBoxStyle.YesNo);
				num2 = 4;
				bool flag;
				if (num3 == 6)
				{
					num2 = 5;
					flag = true;
				}
				else
				{
					num2 = 7;
					flag = false;
				}
				num2 = 8;
				StreamWriter streamWriter = clsShared.cFile.OpenOutputStream(text);
				num2 = 9;
				IEnumerator enumerator = cProject.AllChapters().GetEnumerator();
				while (enumerator.MoveNext())
				{
					clsChapter clsChapter = (clsChapter)enumerator.Current;
					num2 = 10;
					if (flag | !clsChapter.Unused)
					{
						num2 = 11;
						string text2 = "";
						num2 = 12;
						int sceneCount = clsChapter.SceneCount;
						for (int i = 1; i <= sceneCount; i++)
						{
							num2 = 13;
							int iD = clsChapter.get_SceneIDByIndex(i);
							num2 = 14;
							if (flag | !cProject.get_SceneByID(iD).Unused)
							{
								num2 = 15;
								text2 = text2 + cProject.get_SceneByID(iD).ConvertedToPlainText() + "\r\n";
							}
							num2 = 16;
						}
						num2 = 17;
						int num4 = 0;
						do
						{
							num2 = 18;
							if (num4 != 13)
							{
								num2 = 19;
								text2 = Strings.Replace(text2, Conversions.ToString(Strings.Chr(97 + num4)), "n");
								num2 = 20;
								text2 = Strings.Replace(text2, Conversions.ToString(Strings.Chr(65 + num4)), "N");
							}
							num2 = 21;
							num4++;
						}
						while (num4 <= 25);
						num2 = 22;
						text2 = Strings.Replace(text2, "_", " ");
						num2 = 23;
						streamWriter.WriteLine(text2);
					}
					num2 = 24;
				}
				num2 = 25;
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
				num2 = 26;
				streamWriter.Close();
				num2 = 27;
				clsShared.cSubs.NormalMouse();
				num2 = 28;
				clsShared.cFile.RunFile(cProject.ProjectPath());
				num2 = 29;
				clsShared.cLang.TransMsgBox("Your Nano-obfuscated file has been saved to " + text);
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num5 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_02e5: Could not find block for branch target IL_02b1*/;
			}
			if (num5 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
